/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.model.core;

import java.util.Date;


/**
 * <p>Content page with virtual uri.</p>
 * <p>Content Page (CP) is a page which is based on particular {@link Layout}. It
 * inherits {@link ContentField}s, menu structure (through {@link MenuItem}s)
 * and tiles definition used to figure out how the page will look. Content Page
 * has an URI that will identify it to the system, and that page will be output
 * to the user responding to request to that URI.</p>
 * <p>As other {@link Localizable}s, Content Page contains {@link ContentField}s.
 * Their positions on the page are specified by corresponding Layout.</p>
 * <p>Content Pages are more <em>static</em>, and {@link ActionPage}s are more
 * <em>dynamic</em>, because Content Pages are based on fixed Layout.</p>
 * <p><b>active</b> property means for Active Page that it's ready for publication.
 * If a Content Page is not ready for publication, then when user tries to view
 * such page, he will get HTTP 503 (Service Unavailable) error code.</p>
 * <p>
 * Two dates are assigned to each content page: publication date and expiration
 * date. When page is created, it's made active if publication date is not
 * in future, else it becomes inactive. Then, when publication date comes, page
 * is made active. Expiration date has a contrary effect: when it comes,
 * content page becomes inactive.
 * </p>
 * <p>Every Content Page has a list of {@link Role}s that are allowed to access it.
 * If that list is empty, everyone is allowed to access such Content Page, otherwise
 * only users that have at least one role from that list can access the Content Page.</p>
 * <p><a href="ContentPage.java.html"><i>View Source</i></a>
 * </p>
 * <p/>
 *
 * @author Andrey Grebnev <a href="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
 * @version $Revision: 1.29 $ $Date: 2007/04/01 14:51:04 $
 * @struts.form include-all="false" extends="BaseForm"
 * @hibernate.joined-subclass table="`al_core_content_page`" lazy="false"
 * @hibernate.joined-subclass-key column="`page_id`"
 */
public class ContentPage extends Page {

	//~ Instance variables

    /**
     * Layout on which this content page is based
     */
	protected Layout layout = null;
    /**
     * <p>The max age of content page response in browser. If the max age is lesser than zero - no-cache.<p>
     * <p>If value is <code>null</code> it means the default value from global properties will be used</p>
     */
    protected Long cacheMaxAge = null;

	/**
	 * Publication date of content page
	 */
	protected Date publicationDate = new Date();

	/**
	 * Date when this page must be set inactive
	 */
	protected Date expirationDate = new Date();

    //~ Methods

	/**
	 * Returns the layout of this content page
	 *
	 * @return layout
	 * @hibernate.many-to-one column="`layout_id`" not-null="true" outer-join="false" lazy="false"
	 * @struts.form-field
	 */
	public Layout getLayout() {
		return layout;
	}

	/**
     * Sets the layout of this content page
     *
	 * @param layout the layout to set
	 */
	public void setLayout(Layout layout) {
		this.layout = layout;
	}

    /**
     * <p>Returns the max age of content page response in browser. If the max age is less than zero - no-cache.<p>
     * <p>If value is <code>null</code> it means the default value from global properties will be used</p>
     *
     * @return max age
     * @hibernate.property column="`cache_maxage`" not-null="false"
     * @struts.form-field
     * @struts.validator type="integer"
     * @struts.validator-args arg0resource="core.contentPage.form.cacheMaxAge"
     */
    public Long getCacheMaxAge() {
        return cacheMaxAge;
    }

    /**
     * Sets max age for caching this page
     *
     * @param cacheMaxAge max age
     * @see ContentPage#getCacheMaxAge()
     */
    public void setCacheMaxAge(Long cacheMaxAge) {
        this.cacheMaxAge = cacheMaxAge;
    }

    /**
     * Returns publication date of this page. If the page is created before
     * its publication date, it's made inactive; it will become active when
     * comes date of publication.
     *
     * @return publication date
     * @struts.form-field
     * @struts.validator type="required, customdate"
     * @struts.validator-args arg0resource="core.contentPage.form.publicationDate"
     * @hibernate.property column="`publication_date`" not-null="false" type="date"
     */
    public Date getPublicationDate() {
        return publicationDate;
    }

    /**
     * Sets publication date of this page. If the page item is created before
     * its publication date, it's made inactive; it will become active when
     * comes date of publication.
     *
     * @param publicationDate publication date
     */
    public void setPublicationDate(Date publicationDate) {
        this.publicationDate = publicationDate;
    }

    /**
     * Returns expiration date of this page (it's the date when page becomes
     * inactive).
     *
     * @return expiration date
     * @struts.form-field
     * @struts.validator type="required, customdate"
     * @struts.validator-args arg0resource="core.contentPage.form.expirationDate"
     * @hibernate.property column="`expiration_date`" not-null="false" type="date"
     */
    public Date getExpirationDate() {
        return expirationDate;
    }

    /**
     * Sets expiration date of this page (it's the date when page becomes
     * inactive).
     *
     * @param expirationDate expiration date
     */
    public void setExpirationDate(Date expirationDate) {
        this.expirationDate = expirationDate;
    }
}
